(function () {
	var serverData = {};
    var serverTable;
    //查询1
    jQuery('#search_btn').on('click',function(){
        /*serverData.year=jQuery('#sel').val();
        serverData.month=jQuery('#sele').val();*/
        var begindate = jQuery('#sel').val()+"-"+jQuery('#sele').val()+"-"+1;
        //如果为12月，年进1
        if(parseInt(jQuery('#sele').val())==12){
        	var enddate = (parseInt(jQuery('#sel').val())+1)+"-"+01+"-"+01;
        }else{
        	if(parseInt(jQuery('#sele').val())+1 <10){
        		var enddate = (jQuery('#sel').val())+"-0"+(parseInt(jQuery('#sele').val())+1)+"-"+01;
        	}else{
        		var enddate = (jQuery('#sel').val())+"-"+(parseInt(n)+1)+"-"+01;
        	}
        }
        serverData.begindate=begindate;
        serverData.enddate=enddate;
        serverTable.draw();
    })
    //撤销查询
    jQuery('#reset').on("click",function()
    {
         jQuery('#search').val('');
        serverData.key ='';
        serverTable.draw();
    });
    
    jQuery(document).ready(function () { 
//    	var begindate = "2015-01-01";
//    	var enddate = "2018-01-01";
    	var date = new Date();
    	//本月1日
    	var begindate = date.getFullYear()+"-"+(date.getMonth()+1)+"-01";
    	if(date.getMonth()+1 == 12){
    		//12月年+1；为明年1月1日
    		var enddate = (date.getFullYear()+1)+"-01-01";
    	}else{
    		var enddate = date.getFullYear()+"-"+(date.getMonth()+2)+"-01";
    	}
    	serverData.begindate=begindate;
        serverData.enddate=enddate;
        serverTable = jQuery('#dataTable').DataTable({
        	"serverSide": true,
        	"ordering": false,
        	"pageLength" : -1,
        	"ajax": {
        		"dataType": "json",
        		"type": "post",
        		"cache": false,
        		"url":window.rootPath+ '/ui/analyzeStaff/getTwo',
        		"data": function (d) {
        			return $.extend({}, d, serverData);
        		}
        	},
            "columns" : [{
			                data: null,
			                defaultContent : ""// 排序   1
			            },
			            {
        	                data: 'sAreaName'
        	                
        	            },
        	            {
        	                data: 'name'
        	                
        	            },
        	            {
        	                data: 'sszhujiyufukuan'
        	                
        	            },
        	            {
       		        	 	data: 'sszhujijindukuan'
        	            },
        	            {
        	                data: 'sszhujifahuokuan'
        	                
        	            },
        	            {
        	                data: 'sszhujiyanshoukuan'
        	                
        	            },
        	            {
        	                data: 'sszhujitiaoshikuan'
        	                
        	            },
        	            {
        	                data: 'sszhujizhibaojin'
        	                
        	            },
        	            {
        	                data: 'sszhujiyunfei'
        	            },
        	            {
        	                data: 'sszjheji'
        	            },
        	            {
        	                data: 'yszhujiyufukuan'
        	            },
        	            {
        	                data: 'ysshujijindukuan'
        	            },
        	            {
        	                data: 'yszhujifahuokuan'
        	            },
        	            {
        	                data: 'yszhujiyanshoukuan'
        	            },
        	            {
        	                data: 'yszhujitiaoshikuan'
        	            },
        	            {
        	                data: 'yszhujizhibaojin'
        	            },
        	            {
        	                data: 'yszhujiyunfei'
        	            },
        	            {
        	                data: 'YSZJTotal'
        	            },
        	            {
        	                data: 'zjbl'
        	            },
        	            {
        	                data: 'ssbeijianyufukuan'
        	            },
        	            {
        	                data: 'ssbeijianjindukuan'
        	            },
        	            {
        	                data: 'ssbeijianfahuokuan'
        	            },
        	            {
        	                data: 'ssbeijianyanshoukuan'
        	            },
        	            {
        	                data: 'ssbeijiantiaoshikuan'
        	            },
        	            {
        	                data: 'ssbeijianzhibaojin'
        	            },
        	            {
        	                data: 'ssbeijianyunfei'
        	            },
        	            {
        	                data: 'ssbjheji'
        	            },
        	            {
        	                data: 'ysbeijianyufukuan'
        	            },
        	            {
        	                data: 'ysbeijianjindukuan'
        	            },
        	            {
        	                data: 'ysbeijianfahuokuan'
        	            },
        	            {
        	                data: 'ysbeijianyanshoukuan'
        	            },
        	            {
        	                data: 'ysbeijiantiaoshikuan'
        	            },
        	            {
        	                data: 'ysbeijianzhibaojin'
        	            },
        	            {
        	                data: 'ysbeijianyunfei'
        	            },
        	            {
        	                data: 'ysbjheji'
        	            },
        	            {
        	                data: 'bjbl'
        	            }],
            "drawCallback": function (oSettings) {
                var k = 0;
                var total = oSettings.aiDisplay.length + oSettings._iDisplayStart;

                for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
                    $('td:eq(0)', oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
                    k++;
                }
            }
        });
	    //下拉选
	    var sel = document.getElementById('sel');
		var date = new Date();
		for(var j=2;j>=0;j--){
			var opt = document.createElement("option");
			opt.value = date.getFullYear()+j;
			opt.innerHTML = (date.getFullYear()+j);
			sel.appendChild(opt);
			if(j==0){
				opt.selected=true
			}
		}
		for(var i=0;i<5;i++)
		{
			var opt = document.createElement("option");
			opt.value = date.getFullYear()-i-1;
			opt.innerHTML = (date.getFullYear()-i-1);
			sel.appendChild(opt);
		}
		var sele = document.getElementById('sele');
		for(var k=1;k<=12;k++){
			var a  = k;
			if(a<10){
				a = "0"+a;
			}
			var opt = document.createElement("option");
			opt.value = a;
			opt.innerHTML = (a);
			sele.appendChild(opt);
			if(date.getMonth()+1==a){
				opt.selected=true
			}
		}
    });
	//document.body.appendChild(sel);
})();
/*window.onload = function()
{
	
}*/